package lcr;

public class Test0047 {
}

class Solution0047_1 {
    public TreeNode pruneTree(TreeNode root) {
        return dfs(root)? null:root;
    }

    public boolean dfs(TreeNode root){
        if (root==null) return true;
        boolean l = dfs(root.left);
        boolean r = dfs(root.right);
        if (root.val==1){
            if (l) root.left = null;
            if (r) root.right = null;
            return false;
        }else {
            if (l&&r) return true;
            if (l) root.left = null;
            if (r) root.right = null;
            return false;
        }
    }
}